package com.yunji.cabinet.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.yunji.cabinet.domain.ContainerDO;
import com.yunji.storage.dto.StorageFiledDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.cabinet.mapper
 * @FileName CabinetMapper.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-03-30 19:50:14
 * @Description 货柜业务数据交互
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-03-30 19:50:14		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
public interface CabinetMapper extends MPJBaseMapper<ContainerDO> {

    /**
     * @Title resetCabinet
     * @Desc 重置货柜二维码信息
     * @Date 2024-06-07 16:21:27.659
     * @Return int 重置记录
     */
    @Select("UPDATE t_container SET qrcode = null WHERE container_id = #{containerId} AND del_flag = 0")
    int resetCabinetQrcode(Long containerId);

    /**
     * @param param 过滤条件
     * @Title searchTableField
     * @Desc 匹配表字段信息
     * @Date 2024-09-09 11:40:46.462
     * @Return List<String> 匹配结果
     */
    @Select("<script>      SELECT" +
            "        DISTINCT ${param.searchFiled}" +
            "        FROM" +
            "        v3_belong b" +
            "        LEFT JOIN t_container c ON b.belong_id = c.belong_id" +
            "        LEFT JOIN s_agent_user au ON b.agent_id = au.id" +
            "        LEFT JOIN t_site ts ON b.site_id = ts.id" +
            "        WHERE c.del_flag = 0 AND b.del_flag = 0" +
            "        <if test=\"param.containerName != null\">AND c.container_name LIKE concat('%',#{param.containerName},'%')</if>" +
            "        <if test=\"param.agentName != null\">AND au.agent_name LIKE concat('%',#{param.agentName},'%')</if>" +
            "        <if test=\"param.siteName != null\">AND ts.site_name LIKE concat('%',#{param.siteName},'%')</if>" +
            "        <if test=\"param.agentId != null\">AND b.agent_id = #{param.agentId}</if>" +
            "        <if test=\"param.managerId != null\">AND b.site_id = #{param.managerId}</if>" +
            "        <if test=\"param.belongId != null\">AND b.belong_id = #{param.belongId}</if>" +
            "        <if test=\"param.parentId != null\">AND b.parent_id = #{param.parentId}</if> </script>")
    List<String> searchTableField(@Param("param") StorageFiledDTO param);
}
